package com.coisini.mapper;

import com.coisini.entity.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AddressBookMapper {

    /**
     * 新增地址
     * @param addressBook
     */
    void insert(AddressBook addressBook);

    /**
     * 查询当前用户所有的地址信息
     * 根据当前用户的id查询
     * @param addressBook
     * @return
     */
    List<AddressBook> list(AddressBook addressBook);

    /**
     * 根据用户id 将当前用户所有的地址设置为非默认
     * @param addressBook
     */
    @Update("update address_book set is_default = #{isDefault} where user_id =#{userId} ")
    void updateIsDefaultGetByUserId(AddressBook addressBook);

    /**
     * 修改地址
     * @param addressBook
     */

    void update(AddressBook addressBook);

    /**
     * 根据id查询地址
     * @param id
     * @return
     */
    @Select("select * from address_book where  id =#{id}")
    AddressBook getById(Long id);

    /**
     * 根据id删除地址
     * @param id
     */
    @Delete("delete from address_book where id = #{id}")
    void deleteById(Long id);
}
